package com.agileboot.domain.performance.score.model;

import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.performance.score.db.UserScoreRecordEntity;
import com.agileboot.domain.performance.score.db.UserScoreRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 用户分数记录模型工厂
 */
@Component
@RequiredArgsConstructor
public class UserScoreRecordModelFactory {

    private final UserScoreRecordService userScoreRecordService;

    public UserScoreRecordModel loadById(Long id) {
        UserScoreRecordEntity entity = userScoreRecordService.getById(id);
        if (entity == null) {
            throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, id, "用户分数记录");
        }
        return new UserScoreRecordModel(entity, userScoreRecordService);
    }

    public UserScoreRecordModel create() {
        return new UserScoreRecordModel(userScoreRecordService);
    }

}

